package model.surface;

/**
 * Class implemented using singleton pattern. The class is container for current
 * screen width and height, and scales the images and the game info depending on
 * these screen sizes.
 * 
 * @author EvilTeam
 * 
 */
public class Scale {

	private static final int SCALE_FACTOR_FOR_ICON_Y = 6;
	private static final int SCALE_FACTOR_FOR_ICON_X = 36;
	private static final int TABLET_SCREEN = 1280;
	private static final int TYPICAL_PHONE_SCREEN = 800;
	private static final float SCALE_FACTOR_FOR_NONTYPICAL_DEVICES = 1.4f;
	private static final float SCALE_FACTOR_FOR_TABLETS = 1.1f;
	private static final float SCALE_FACTOR_FOR_TYPICAL_PHONE_SCREENS = 1.7f;
	private static final int ICON_HEIGHT_SCALE_FACTOR = 5;
	private static final int ICON_WIDTH_SCALE_FACTOR = 9;
	private static final float WIDTH_SCALE_FACTOR = 2.71f;
	private static final float HEIGHT_SCALE_FACTOR = 3.05f;

	private static int screenHeight, screenWidth;
	private static Scale scale = null;

	private Scale() {
	}

	/**
	 * Sets the screen height and width for scale object.
	 * @param screenHeight
	 * @param screenWidth
	 */
	public static void scaleFactory(int screenHeight, int screenWidth) {
		setScreenHeight(screenHeight);
		setScreenWidth(screenWidth);
	}

	/**
	 * Returns instance of the scale object.
	 * @return
	 */
	public static Scale getInstanceOfScaleClass() {
		synchronized (Scale.class) {
			if (scale == null) {
				scale = new Scale();
			}
		}
		return scale;
	}

	public static int getScreenHeight() {
		return screenHeight;
	}

	public static void setScreenHeight(int screenHeight) {
		if (screenHeight > 0)
			Scale.screenHeight = screenHeight;
	}

	public static int getScreenWidth() {
		return screenWidth;
	}

	public static void setScreenWidth(int screenWidth) {
		if (screenWidth > 0)
			Scale.screenWidth = screenWidth;
	}

	/**
	 *
	 * @return scaled height of the images.
	 */
	public float getScaledHeightForImages() {
		return getScreenHeight() / HEIGHT_SCALE_FACTOR;
	}

	/**
	 * 
	 * @return scaled width of the images.
	 */
	public float getScaledWidthForImages() {
		return getScreenWidth() / WIDTH_SCALE_FACTOR;
	}

	/**
	 * 
	 * @return scaled width of the icons(upgrade and sell icons).
	 */
	public int getScaledWidthForIcons() {
		return getScreenWidth() / ICON_WIDTH_SCALE_FACTOR;
	}

	/**
	 * 
	 * @return scaled height of the icons(upgrade and sell icons).
	 */
	public int getScaledHeightForIcons() {
		return getScreenHeight() / ICON_HEIGHT_SCALE_FACTOR;
	}

	/**
	 * 
	 * @return scaled x position of the icons(upgrade and sell icons).
	 */
	public int scaledXPointForIcons() {
		return getScreenWidth() / SCALE_FACTOR_FOR_ICON_X;
	}

	/**
	 * 
	 * @return scaled y position of the icons(upgrade and sell icons).
	 */
	public int scaledYPointForIcons() {
		return getScreenHeight() / SCALE_FACTOR_FOR_ICON_Y;
	}

	/**
	 * Returns scale factor for towers range depending on different screen
	 * sizes.
	 * 
	 * @return
	 */
	public float getScaleFactorForRange() {
		if (screenWidth <= TYPICAL_PHONE_SCREEN)
			return SCALE_FACTOR_FOR_TYPICAL_PHONE_SCREENS;
		else if (screenWidth >= TABLET_SCREEN)
			return SCALE_FACTOR_FOR_TABLETS;
		else
			return SCALE_FACTOR_FOR_NONTYPICAL_DEVICES;
	}
}
